package com.yh.view;


import com.yh.javabean.Admin;
import com.yh.serivicelmpl.MainServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@WebServlet("/adminlogin")
public class adminlogin extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        MainServiceImpl mainSerivice = new MainServiceImpl();

       Admin adminlogin = mainSerivice.adminLogin(username, password);

        System.out.println(adminlogin);
        JSONObject jsonObject = new JSONObject();
        jsonObject.element("code",200);
        jsonObject.element("msg","查询成功");

        jsonObject.element("data", JSONArray.fromObject(adminlogin));

        PrintWriter writer = response.getWriter();
        writer.println(jsonObject);
    }
}
